// plugins/adapt.js
import Adapt from './lib/adapt';

export const AdaptPlugin = {
    install(app, options) {
        // 初始化屏幕适配
        const scale = Adapt.init(options);

        // 全局注册屏幕适配工具
        app.config.globalProperties.$Adapt = Adapt;

        // 提供全局计算属性
        app.provide('AdaptScale', scale);

        // 添加指令
        app.directive('adapt-font', {
            mounted(el, binding) {
                const fontSize = binding.value || 14;
                const scale = Adapt.getScale();
                el.style.fontSize = `${fontSize * scale}px`;
            },

            updated(el, binding) {
                const fontSize = binding.value || 14;
                const scale = Adapt.getScale();
                el.style.fontSize = `${fontSize * scale}px`;
            }
        });
    }
};
